﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.RobotJog.Controls.Joints.AllJointsLayoutBuilder
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using Tecnomatix.Engineering.PrivateImplementationDetails;


namespace DnProcessSimulateCommands.RobotJog.Controls.Joints;

internal class AllJointsLayoutBuilder(
  CUiJointsControl jointsControl,
  CApRJRobotJogJointsLogic jointJogApplication) : JointsLayoutBuilder(jointsControl, jointJogApplication)
{
  public override void InitGrid() => base.InitGrid();

  public override void AditionalGridInit()
  {
    this.jointJogApplication.ShowDependentJoints(this.jointsControl.ShowDependentJoints);
    this.jointsControl.IsEnabled = true;
  }

  private bool ShouldAddThisJoint(CUiJointNodeData jointData)
  {
    bool flag = true;
    if (TxFeatureManager.CheckFeature("USER_FORWARD"))
    {
      string niceName = jointData.NiceName;
      if (niceName.Contains("Platform") || niceName.Contains("AxisDistance") || niceName.Contains("Elbow") || niceName.Contains("LowerArmAux") || niceName.Contains("Telescope"))
        flag = false;
    }
    return flag;
  }

  public override void AddJointToGrid(CUiJointNodeData jointData)
  {
    if (!this.ShouldAddThisJoint(jointData))
      return;
    string name = this.jointsControl.jointsGrid.ColumnDefinitions[this.jointsControl.jointsGrid.ColumnDefinitions.Count - 1].Name;
    this.jointJogApplication.SaveExternalJointValue(jointData);
    StackPanel stackPanel1 = new StackPanel();
    stackPanel1.Orientation = Orientation.Horizontal;
    stackPanel1.Tag = (object) jointData;
    StackPanel stackPanel2 = stackPanel1;
    UIElementCollection children1 = stackPanel2.Children;
    Image element1 = new Image();
    element1.Source = jointData.NodeIcon;
    element1.Margin = new Thickness(4.0, 0.0, 4.0, 0.0);
    children1.Add((UIElement) element1);
    UIElementCollection children2 = stackPanel2.Children;
    TextBlock element2 = new TextBlock();
    element2.Text = jointData.NiceName;
    element2.Margin = new Thickness(0.0, 0.0, 4.0, 0.0);
    element2.VerticalAlignment = VerticalAlignment.Center;
    children2.Add((UIElement) element2);
    Border jointNameBorder = new Border()
    {
      BorderThickness = new Thickness(1.0, 0.0, 1.0, 1.0)
    };
    jointNameBorder.Child = (UIElement) stackPanel2;
    if (name != ColumnsIDS.Joint)
      jointNameBorder.Margin = new Thickness(0.0, 0.0, -7.0, 0.0);
    Border border = new Border();
    border.Padding = new Thickness(2.0, 4.0, 2.0, 4.0);
    border.Margin = new Thickness(0.0, 0.0, -7.0, 0.0);
    Border sliderBorder = border;
    sliderBorder.Child = (UIElement) jointData.SliderControl;
    Border valueBorder = new Border();
    valueBorder.Child = (UIElement) jointData.ValueControl;
    if (name != ColumnsIDS.Value)
      valueBorder.Margin = new Thickness(0.0, 0.0, -7.0, 0.0);
    Border percentageBorder = new Border();
    percentageBorder.Child = (UIElement) jointData.PercentageControl;
    if (name != ColumnsIDS.Percentage)
      percentageBorder.Margin = new Thickness(0.0, 0.0, -7.0, 0.0);
    Border lowSoftLimitBorder = new Border();
    lowSoftLimitBorder.Child = (UIElement) jointData.LowSoftLimitControl;
    if (name != ColumnsIDS.LowerLimit)
      lowSoftLimitBorder.Margin = new Thickness(0.0, 0.0, -7.0, 0.0);
    Border upperSoftLimitBorder = new Border();
    upperSoftLimitBorder.Child = (UIElement) jointData.UpperSoftLimitControl;
    if (name != ColumnsIDS.UpperLimit)
      upperSoftLimitBorder.Margin = new Thickness(0.0, 0.0, -7.0, 0.0);
    this.jointsControl.AddRowToGrid(jointData, jointNameBorder, sliderBorder, valueBorder, percentageBorder, lowSoftLimitBorder, upperSoftLimitBorder);
  }

  public override int JointsCountInGrid() => this.jointsControl.jointsGrid.RowDefinitions.Count - 1;

  public override CUiJointNodeData GetJoinData(FrameworkElement element)
  {
    return this.GetJoinData(Grid.GetRow((UIElement) element.Parent));
  }

  public CUiJointNodeData GetJoinData(int row)
  {
    return (this.jointsControl.jointsGrid.Children.OfType<Border>().FirstOrDefault<Border>((Func<Border, bool>) (elem => Grid.GetRow((UIElement) elem) == row && Grid.GetColumn((UIElement) elem) == 0)).Child as FrameworkElement).Tag as CUiJointNodeData;
  }
}
